<?php
/**
 * Created by PhpStorm.
 * User: sqq
 * Date: 2018/05/24
 * Time: 上午11:45
 */
class KingGloryBrowse extends Eloquent
{
    protected $primaryKey = 'id';
    protected $table = "kingglory_browse";

    public static function BrowseOne($anchors,$source){
        $browse = KingGloryBrowse::where("anchors",$anchors)->where("source",$source)->first();
        return $browse;
    }

    public static function InsertBrowse($anchors,$source){
        $browse = new KingGloryBrowse();
        $browse->anchors = $anchors;
        $browse->source = $source;
        $browse->num = '1';
        $browse->created_at = date("Y-m-d H:i:s",time());
        $browse->updated_at = date("Y-m-d H:i:s",time());
        $browse->save();
        $browse = KingGloryBrowse::where("anchors",$anchors)->where("source",$source)->select("id","anchors","source","num")->first();
        return $browse;
    }

    public static function UpdatedBrowse($num,$id){
        $time = date("Y-m-d H:i:s",time());
        DB::update("update kingglory_browse set num=1+?, updated_at=? where id=?",array($num,$time,$id));
        $browse = KingGloryBrowse::where("id",$id)->select("id","anchors","source","num")->first();
        return $browse;
    }
}